Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative urls for fastboot and ember-data #128

Closed
wants to merge 2 commits into from
Closed

Allow relative urls for fastboot and ember-data #128

wants to merge 2 commits into from

Conversation

RobbieTheWagner
Copy link

@RobbieTheWagner RobbieTheWagner commented Aug 25, 2018

Copied over the buildServerUrls function from ember-fetch-adapter to allow relative urls with fastboot and ember-data.

@RobbieTheWagner RobbieTheWagner changed the title Use ember-fetch-adapter to allow absolute urls for ember-data Use ember-fetch-adapter to allow relative urls for ember-data Aug 25, 2018
@RobbieTheWagner RobbieTheWagner changed the title Use ember-fetch-adapter to allow relative urls for ember-data Allow relative urls for ember-data Aug 25, 2018
@RobbieTheWagner RobbieTheWagner changed the title Allow relative urls for ember-data Allow relative urls for fastboot and ember-data Aug 25, 2018
Copy link
Collaborator

@nlfurniss nlfurniss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a little more to the description of this PR about what this change is trying to accomplish?

return owner && owner.lookup('service:fastboot');
}),

protocol: computed(function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use CPs with dependent keys? Can these be set in init?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For verifying if Fastboot is used isn't this the preferred way to do it in an addon—to avoid an error if the consumer doesn't have Fastboot installed?

One thing to note is that someone may use your addon in an app that doesn't have FastBoot installed. In that case, if your addon tries to inject the fastboot service, they'll get an exception saying the fastboot service cannot be found.

Instead, you can write a computed property that uses the low-level getOwner functionality to lookup the fastboot service directly.

https://ember-fastboot.com/docs/addon-author-guide#accessing-the-fastboot-service

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrism Yea you're absolutely right, thansk for pointing out!

@RobbieTheWagner
Copy link
Author

@nlfurniss I copied this stuff from https://github.com/tchak/ember-fetch-adapter/blob/master/addon/index.js

It allows users of this mixin to make requests when in fastboot. Without these changes, you get an error with node-fetch complaining about only absolute URLs are supported.

@RobbieTheWagner
Copy link
Author

I have been speaking with @tchak about this. Might be good for him to weigh in here 😃

@RobbieTheWagner
Copy link
Author

@nlfurniss @tchak any updates on this?

@chrism
Copy link

chrism commented Oct 29, 2018

I've been getting this error too when using with Fastboot after following the instructions.

Error while processing route: index Only absolute URLs are supported TypeError: Only absolute URLs are supported

It would be great to see this merged.

@RobbieTheWagner
Copy link
Author

@nlfurniss @rwjblue what do we need to do to get this merged?

@nlfurniss
Copy link
Collaborator

Can you rebase and resolve the conflicts? Also what about tests?

@RobbieTheWagner
Copy link
Author

@nlfurniss yes, I can rebase, but tests would need a very special setup to force fastboot and ember-data, and I am not sure it would be something we could easily do. If I rebase, can we merge as is? This has been open quite awhile.

return owner && owner.lookup('service:fastboot');
}),

protocol: computed(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @param url
* @returns {*}
*/
buildServerURL(url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildServerURL sounds Fastboot specific, maybe change the method name or move the non-fastboot branch to _fetchRequest? This function can also be unit tested.

return `${protocol}${url}`;
} else if (!httpRegex.test(url)) {
try {
return `${protocol}//${host}${url}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this throw?

@RobbieTheWagner
Copy link
Author

I copied this stuff from https://github.com/tchak/ember-fetch-adapter/blob/master/addon/index.js

It allows users of this mixin to make requests when in fastboot. Without these changes, you get an error with node-fetch complaining about only absolute URLs are supported.

@xg-wang I just copied all this, as mentioned previously. Since I know it works currently, and it's copied from this other addon, I am not sure what the best way to proceed is.

@xg-wang
Copy link
Member

xg-wang commented Nov 16, 2018

Close by #143

@RobbieTheWagner RobbieTheWagner deleted the server-side branch November 17, 2018 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants